package golang

import "gitee.com/allowall-package/goutil/fn"

// 工厂接口方法
type FactoryMethodOption interface {
	Exec(a, b int) int
}

// 工厂接口
type FactoryMethod interface {
	Create() FactoryMethodOption
}

// ---------------分割线---------------

// 加法计算方法类
type FactoryMethodAddOption struct{}

func (f *FactoryMethodAddOption) Exec(a, b int) int {
	return a + b
}

// 加法计算工厂类
type FactoryMethodAdd struct{}

func (f *FactoryMethodAdd) Create() FactoryMethodOption {
	return &FactoryMethodAddOption{}
}

// ---------------分割线---------------

// 减法计算方法类
type FactoryMethodSubOption struct{}

func (f *FactoryMethodSubOption) Exec(a, b int) int {
	return a - b
}

// 减法计算工厂类
type FactoryMethodSub struct{}

func (f *FactoryMethodSub) Create() FactoryMethodOption {
	return &FactoryMethodSubOption{}
}

// ---------------分割线---------------

// 测试方法
func FactoryMethodTest() {
	var method FactoryMethod
	method = &FactoryMethodAdd{}
	fn.Dump(fn.FuncInfo(), method.Create().Exec(1, 2))
}
